<?php
	
	class Ya{
	 var $ch;
	
		function __construct() {
        $this->ch= curl_init();
		}
		
		function get_page($url,$post=null,$ssl=null,$header=null,$follow=null) {
				//$ch = curl_init($url);	
				curl_setopt ($this->ch, CURLOPT_URL, $url);
				if($header != null) curl_setopt($this->ch, CURLOPT_HEADER, 1);
				curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, $follow);			
				curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1);
				curl_setopt($this->ch, CURLOPT_TIMEOUT, 10);
				curl_setopt($this->ch, CURLOPT_CONNECTTIMEOUT, 10);
				if($ssl == null) {
					curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, false);
					curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, false);
				}	
				if($post != null){
					curl_setopt($this->ch, CURLOPT_POST, 1);
					curl_setopt($this->ch, CURLOPT_POSTFIELDS,$post);
				}	
				curl_setopt($this->ch, CURLOPT_COOKIEJAR, dirname(__FILE__) . '/c.txt');
				curl_setopt($this->ch, CURLOPT_COOKIEFILE, dirname(__FILE__) . '/c.txt');
				curl_setopt($this->ch, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; Linux x86_64; rv:9.0.1) Gecko/20100101 Firefox/8.0.1");
				$res = curl_exec($this->ch);
				//curl_close($ch);					
				return $res;
			}		
		
		function auth_yaRU($login,$pass) {		
			$time = time();
      $ssl=null;
			$url = "https://passport.yandex.ru/passport?mode=auth&from=mail";
			$post = "retpath=http%3A%2F%2Fmail.yandex.ru%2F&login=" . $login . "&passwd=" . $pass . "&timestamp=" . $time;
			$header = "1";
			$page = $this->get_page($url,$post,$ssl,$header,$f=1);
			$page2 = $this->get_page("https://mail.yandex.ru/lite/inbox");
			return $page2;
			
		}
		
	}

?>
